package com.ellricky.newtv

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import com.andr.common.ui.fragment.BaseFragment
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.ui.web.*
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.newtv.const.TvConst

import kotlinx.android.synthetic.main.fragment_video_preview.*
import xyz.doikki.videocontroller.StandardVideoController

class NewTvVideoPreviewFragment : BaseFragment<Void, BasePresenter<Void>>(), OnPageListener {

    private val imageList: ArrayList<String> by lazy {
        arguments?.getStringArrayList(TvConst.KEY_IMAGE) ?: arrayListOf()
    }

    private val mHandler = Handler(Looper.getMainLooper())

    companion object {
        fun newInstance(imageList: ArrayList<String>): NewTvVideoPreviewFragment {
            val args = Bundle()
            args.putStringArrayList(TvConst.KEY_IMAGE, imageList)
            val fragment = NewTvVideoPreviewFragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun getContentLayout(): Int {
        return R.layout.fragment_video_preview
    }

    override fun initUIView(p0: View?) {
        if (imageList.isNullOrEmpty()) {
            return
        }
        val controller = StandardVideoController(requireContext())
        controller.addDefaultControlComponent("", false)

        val videoPath = imageList.first()
        player.setUrl(videoPath)
        player.setVideoController(controller)

//        WebUtils.initWebviewSettings(web_view)
//
//
//
//        web_view.requestFocus(View.FOCUS_DOWN)
//
//        web_view.webChromeClient = MyWebChromeClient(pb_web, this)
//        val webViewClient = MyWebViewClient(requireActivity())
//        web_view.webViewClient = webViewClient
//
//        web_view.loadUrl(imageList.first())
    }

    override fun onDestroyView() {
        super.onDestroyView()
        player.release()
    }

    override fun setErrorPage(isShow: Boolean) {

    }
}